<?php
// +----------------------------------------------------------------------
// | Author: wyd 2025/11/2
// | DESC: 
// +----------------------------------------------------------------------
declare (strict_types=1);

require_once __DIR__ . '/../../vendor/autoload.php';

Swoole\Coroutine\run(function () {
    go(function () {
        $pool = new \Study\swoole\pool\Pdopool();
        $pool->initPool();


   for ($i= 0 ; $i<5; $i++){
       go(function () use ($pool,$i){
           /** @var \PDO $conn */
           $conn = $pool->getConnection();

           // defer 会在协程退出时自动执行
           defer(fn () => $pool->close($conn));

           $status = $conn->query('select '.$i);
           $status->setFetchMode(\PDO::FETCH_ASSOC);
           $rows = $status->fetchAll();
           var_dump($rows);
       });
   }

        while (true) {
            \Swoole\Coroutine::sleep(1);
        }
    });
});